package com.atgugui.eduservice.controller;


import com.atgugui.commonutils.Result;
import com.atgugui.eduservice.entity.EduVideo;
import com.atgugui.eduservice.service.EduVideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-08-29
 */
@Api(tags = "视频小节控制层")
@RestController
@RequestMapping("/eduservice/edu-video")
@CrossOrigin
public class EduVideoController {

    @Autowired
    private EduVideoService eduVideoService;


    @ApiOperation(value = "添加视频小节信息")
    @PostMapping("/addVideo")
    public Result addVideo(@RequestBody EduVideo eduVideo) {
        boolean save = eduVideoService.save(eduVideo);
        return save ? Result.ok() : Result.error();
    }

    @ApiOperation(value = "删除视频小节信息")
    @DeleteMapping("/deleteVideo/{id}")
    public Result deleteVideo(@PathVariable String id) {
        boolean b = eduVideoService.removeVideoByCourseId(id);
        eduVideoService.removeById(id);
        return b ? Result.ok() : Result.error();
    }

    @ApiOperation(value = "更新视频小节信息")
    @PostMapping("/updateVideo")
    public Result updateVideo(@RequestBody EduVideo eduVideo) {
        boolean b = eduVideoService.updateVideo(eduVideo);
        return b ? Result.ok() : Result.error();
    }

    @ApiOperation(value = "根据视频小节id查询数据")
    @GetMapping("/getVideoInfoById/{videoId}")
    public Result getVideoInfoById(@PathVariable String videoId) {
        EduVideo eduVideo = eduVideoService.getById(videoId);
        return Result.ok().data("video",eduVideo);
    }
}

